from flask import current_app
from flask import session

from info.models import User
from . import index_blue
from flask import render_template


@index_blue.route('/')
def index():
    #查询用户id
    user_id = session.get('user_id',None)
    #获取用户数据
    user = None
    if user_id:
        try:
            user = User.query.get(user_id)
        except Exception as e:
            current_app.logger.error(e)
    #通过字典返回页面数据
    data = {
        "user":user.to_index_dict() if user else None
    }

    return render_template('news/index.html',data = data)


@index_blue.route('/favicon.ico')
def favicon():
    return current_app.send_static_file('news/favicon.ico')